package com.cmb;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Store {
    private final List<Product> products = new ArrayList<>();

    public void add(Product product) {
        Product specificProduct = new HashMap<String, Product>() {{
            put("default", new DefaultProduct(product.getName(), product.getSellIn(), product.getQuality()));
            put("Aged Brie", new AgedBrieProduct(product.getName(), product.getSellIn(), product.getQuality()));
            put("Backstage pass", new BackstagePassProduct(product.getName(), product.getSellIn(), product.getQuality()));
            put("Sulfuras", new SulfurasProduct(product.getName(), product.getSellIn(), product.getQuality()));
        }}.get(product.getName());
        this.products.add(specificProduct);
    }

    public void update() {
        products.forEach(Product::update);
    }

    public List<Product> getProducts() {
        return this.products;
    }
}
